/*
*
* Created by yuri at Apr 2, 2011
*
*/



package implementation.server;

import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFuture;

import implementation.shared.IPacket;

public class Connection implements IConnection{

	private Channel _channel;
	
	public Connection(Channel channel) {
		this._channel = channel;
	}
	
	@Override
	public boolean send(IPacket packet) {
		ChannelFuture future = this._channel.write(packet);
		future.awaitUninterruptibly(ServerConnectionManager.TIMEOUT);
		if (!future.isSuccess()) {
			return false;
		}
		return true;
	}

	@Override
	public int getID() {
		return this._channel.getId();
	}

	@Override
	public void close() {
		this._channel.close();
	}

}
